<layout name="page" />
<block name="content">
	<div class="fc-toolbar">
		<div class="fc-left">
			<a onclick="prev();" class="btn"><i class="fa fa-chevron-left"></i></a>
			<a onclick="next();" class="btn"><i class="fa fa-chevron-right"></i></a>
			<a onclick="today();" class="btn">今天</a>
		</div>
		<div class="fc-right">
			<a onclick="day_view();" class="btn">日视图</a>
			<a onclick="add()" class="btn">新建</a>
		</div>
		<div class="fc-center">
			<h2 id="panel"></h2>
		</div><div class="fc-clear"></div>
	</div>
	<div id="calendar"></div>
</block>
<block name="js">
	<script>
		function next() {
			$('#calendar').fullCalendar('next');

		}

		function prev() {
			$('#calendar').fullCalendar('prev');
		}

		function today() {
			$('#calendar').fullCalendar('today');
		}

		function add() {
			window.open("{:url('add')}", "_self");
		}

		function month_view() {
			window.open('{:url("index")}', "_self");
		}

		function day_view() {
			window.open("{:url('day_view')}", "_self");
		}


		$(document).ready(function() {
			/* initialize the calendar
			 -----------------------------------------------------------------*/
			var date = new Date();
			var d = date.getDate();
			var m = date.getMonth();
			var y = date.getFullYear();

			$('#calendar').fullCalendar({
				header : {
					left : 'prev,next today',
					center : 'title',
					right : 'month,agendaDay'
				},
				titleFormat : {
					month : 'YYYY年MMMM', // September 2009
					week : "MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}", // Sep 7 - 13 2009
					day : 'dddd, MMM d, yyyy' // Tuesday, Sep 8, 2009
				},
				firstDay : 1,
				buttonText : {
					prevYear : '去年',
					nextYear : '明年',
					today : '今天',
					month : '月',
					week : '周',
					day : '日'
				},
				timeFormat : 'H:mm',
				dayNamesShort : ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
				monthNames : ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
				eventDrop : function(event, delta, revertFunc) {
					alert(event.title + " was dropped on " + event.start.format());
					if (!confirm("Are you sure about this change?")) {
						revertFunc();
					}
				},
				eventAfterAllRender : function(view) {
					$('#panel').html($('#calendar .fc-toolbar h2').text());
				},
				eventClick : function(event, jsEvent, view) {
					winopen('{:url("read")}&id=' + event.id, 560, 600);
				},
				events : function(start, end, timezone, callback) {
					$.ajax({
						url : '{:url("json")}',
						dataType : 'json',
						data : {
							// our hypothetical feed requires UNIX timestamps
							start_date : start.format('YYYY-MM-DD'),
							end_date : end.format('YYYY-MM-DD')
						},
						success : function(doc) {
							var events = [];
							for (var s in doc) {
								events.push({
									title : doc[s].name,
									start : doc[s].start_time, // will be parsed
									end : doc[s].end_time // will be parsed
								});
							}
							callback(events);
						}
					});
				}
			});

		});

	</script>
</block>
